<template>
    <div class="container">
        <div class="channel">
            <header>
                <router-link to="/">首页 / </router-link>
                推荐机构管理
            </header>
            <div v-if="messageList.length > 0" class="focus-pointer mb30">
                <div class="flex-box-align" style="padding-left: 18px; position: relative; width: 100%;">
                    今日要事：
                    <div class="message">
                        <ul class="marquee_list" :style="{ top: -num + 'px'}" :class="{marquee_top:num}">
                            <li v-for="(item, index) in messageList" :key="index" v-if="messageList && messageList.length">
                                <router-link :to="{name: item.route}">{{item.showMsg}}</router-link>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
            <ul class="company-num-list flex-box-align mb30">
                <li class="flex">
                    <div class="li-top">推荐机构总数</div>
                    <div>{{returnPrice(info.channelUserTotal)}}</div>
                </li>
                <li class="flex">
                    <div class="li-top">一级推荐机构总数</div>
                    <div>{{returnPrice(info.firstChannelUserTotal )}}</div>
                </li>
                <li class="flex">
                    <div class="li-top">本月新增推荐机构</div>
                    <div>{{returnPrice(info.channelUser1Month) }}</div>
                </li>
            </ul>
            <div class="search-modal mb30">
                <div class="" style="margin-bottom: 20px">
                    <span>查询及添加</span>
                    <el-button type="primary" size="small" @click="handleClickSearch">查询</el-button>
                    <el-button type="primary" size="small" @click="handleClickAdd">添加</el-button>

                </div>
                <div class="flex-box-align">
                    <div class="search-item">
                        <div class="search-title">推荐机构名称：</div>
                        <el-input style="width: 54%;" class=""
                                  placeholder="请输入企业名称"
                                  v-model="configList.param.companyNameLike" ></el-input>
                    </div>
                    <!--<div class="search-item">-->
                        <!--<div class="search-title">等级：</div>-->
                        <!--<el-select v-model="value" placeholder="请选择">-->
                            <!--<el-option-->
                                    <!--v-for="item in options"-->
                                    <!--:key="item.value"-->
                                    <!--:label="item.label"-->
                                    <!--:value="item.value">-->
                            <!--</el-option>-->
                        <!--</el-select>-->
                    <!--</div>-->
                    <div class="search-item">
                        <div class="search-title">类型：</div>
                        <el-select filterable v-model="value" placeholder="请选择">
                            <el-option
                                    label="全部"
                                    value="">
                            </el-option>
                            <el-option
                                    v-for="item in options"
                                    :key="item.value"
                                    :label="item.label"
                                    :value="item.value">
                            </el-option>
                        </el-select>
                    </div>
                </div>
            </div>

            <div class="">
                <table-list ref="tableList" :tableConfig='configList'>
                    <el-table-column  slot=""  align="center" label="">
                        <template slot-scope="scope">
                            <span></span>
                        </template>
                    </el-table-column>
                    <el-table-column  slot="status"  align="center" label="当前状态">
                        <template slot-scope="scope">
                            <span v-if="scope.row.coreData.status == 'on'">上线</span>
                            <span v-else-if="scope.row.coreData.status == 'off'">下线</span>
                        </template>
                    </el-table-column>
                    <el-table-column class="btn" label="操作" slot="btn" align="center" >
                        <template slot-scope="scope">
                             <el-button @click="$router.push('/partner/channelDetail?id='+scope.row.userId)"  type="primary" size="small">查看</el-button>
                            <el-button  type="primary" size="small" @click="handleClickOn(scope.row.userId)" style="background: #ED7018;border-color: #ED7018" v-if="scope.row.coreData.status == 'off'">上架</el-button>
                            <el-button  type="primary" size="small" @click="handleClickOff(scope.row.userId)" style="background: #ED7018;border-color: #ED7018" v-else-if="scope.row.coreData.status == 'on'">下架</el-button>
                        </template>
                    </el-table-column>
                </table-list>
            </div>
        </div>
    </div>
</template>

<script>
    import {parseUrlParams} from "../../util";
    let CONSTANT = require('../../constant/constant.js'),
        common = require('../../common.js');
    export default {
        data() {
            return {
                companyName: "",
                options: [{
                    value: 'loan',
                    label: '小贷公司'
                }, {
                    value: 'bank',
                    label: '银行'
                },{
                    value: 'vc',
                    label: 'VC'
                }],
                value: '',
                info:'',
                configList:{
                    url:CONSTANT.URL.CHANNEL.CHANNELLIST,
                    configList:[
                        {
                            label:'推荐机构名称',
                            prop: "coreData.companyName"
                        },
//                        {
//                            label:'等级',
//                            prop: "level"
//                        },
                        {
                            slot: "status"
                        },
                        {
                            slot:'btn',
                        },
                    ],
                    param:{
                        companyNameLike:''
                    },
                    type:'',
                    width:'',
                    isPagination:true,
                },
                num: 0,
                messageList: []
            }
        },
        components: {
            'table-list':() => import('../common/my-table')
        },
        mounted(){
            this.getMessage()
            setInterval( () => {
                this.getMessage()
            }, 120000)
            this.getTotal()
        },
        methods:{
            getMessage() {
                let url = CONSTANT.URL.CALENDAR.MESSAGELIST;
                common.requestAjax(url, {}, {}, (data) => {
                    if(data.status == 200) {
                        this.messageList = data.data.bussData;
                        this.showMarquee(this.num)
                    }
                })
            },
            returnPrice(num){
                return common.returnNum(num)
            },
            getList() {
                this.$refs.tableList.getList();
            },
            getTotal() {
                let url = CONSTANT.URL.REPORT.FINDCHANNELREPORTDATA,
                data = {};
                common.requestAjax(url, JSON.stringify(data), {}, (data) => {
                    if (data.status == 200) {
                        this.info = data.data.bussData;
                    }
                })
            },
            handleClickSearch() {
                 this.$refs.tableList.getList()
            },
            handleClickAdd() {
                this.$router.push("/partner/channelDetail")
            },
            handleClickOn(id) {
                let url = CONSTANT.URL.COMPANY.ONOFFUSER;
                common.requestAjax(url, JSON.stringify({userId: id, status: "on"}), {}, (data) => {
                    if (data.status == 200) {
                        this.$message({
                            message: data.msg,
                            type: "success"
                        })
                        this.getList()
                    }
                })
            },
            handleClickOff(id) {
                let url = CONSTANT.URL.COMPANY.ONOFFUSER;
                common.requestAjax(url, JSON.stringify({userId: id, status: "off"}), {}, (data) => {
                    if (data.status == 200) {
                        this.$message({
                            message: data.msg,
                            type: "success"
                        })
                        this.getList()
                    }
                })
            },
            showMarquee:function (num) {
                if (!this.messageList[0]) return
                this.messageList.push(this.messageList[0]);
                var max = this.messageList.length;
                var that = this;
                let marqueetimer =  setInterval(function(){
                    num++;
                    if(num>=max ){
                        num=0;
                    }
                    that.num=num*30;
                }, 2000);
            }
        }
    }
</script>

<style lang="scss" scoped>
    .message {
        display: block;
        position: relative;
        width: 60%;
        height: 30px;/*关键样式*/
        overflow: hidden;
    }
    .marquee_list{
        display: block;
        position: absolute;
        top:0;
        left: 0;
    }
    .marquee_top{transition: top 0.5s ;}/*关键样式*/
    .marquee_list li{
        height: 30px;/*关键样式*/
        line-height: 30px;/*关键样式*/
        font-size: 14px;
        padding-left: 20px;
        background-color: #fff;
        a {
            color: #333;
        }
    }
    .container {
        .mb30 {
            margin-bottom: 30px;
        }
        .channel {
            header {
                margin: 19px 0;
                font-size: 14px;
                color: #333;
                a {
                    color: #999;
                }
            }
            .focus-pointer {
                font-size: 14px;
                height: 70px;
                line-height: 70px;
                background-color: #fff;
                padding-left: 18px;
                white-space: nowrap;
            }
            /*
            .company-num-list {
                li {
                    cursor: pointer;
                    width:33.33%;
                    height: 152px;
                    padding-top: 48px;
                    background-color: #fff;
                    box-shadow:2px 0px 1px rgba(15,5,9,0.1);
                    margin-right: 1.3%;
                    &:last-child {
                        margin-right: 0;
                    }
                    div:nth-child(1) {
                        font-size: 60px;
                        color: #111111;
                        text-align: center;
                    }
                    div:nth-child(2) {
                        font-size: 16px;
                        color: #666;
                        text-align: center;
                    }
                }
            }
            */
            .search-modal {
                background: #fff;
                padding: 20px 0 25px 18px;
                .btns {
                    width: 73px;
                    height: 40px;
                    text-align: center;
                    line-height: 40px;
                    color: #fff;
                    font-size: 14px;
                    border-radius: 4px;
                    background-color: #ED7018;
                    display: inline-block;
                    cursor: pointer;
                    &:hover{
                        background-color: #ED9000;
                        transition:all .2s linear
                    } 
                }
                .btn-search {
                    margin: 0 20px 0 24px;
                }
                .search-item {
                    width: 25%;
                    display: inline-block;
                    /*margin-right: 2.56%;*/
                    &:last-child {
                        margin-right: 0;
                    }
                    .search-title {
                        display: inline-block;
                    }
                    .el-input {
                        display: inline-block;
                    }
                    .el-select {
                        width: 54%;
                    }
                }
            }
        }
    }
</style>
